/**
 * Definition for singly-linked list.
 * function ListNode(val) {
 *     this.val = val;
 *     this.next = null;
 * }
 */
/**
 * @param {ListNode} head
 * @param {number} k
 * @return {ListNode}
 */

var getKthFromEnd = function (head, k) {
    let dummy = new ListNode()
    dummy.next = head
    let cur = head
    let num = 0
    while (cur) {
        cur = cur.next
        num++
    }
    cur = head
    num = num - k
    while (num) {
        cur = cur.next
        num--
    }
    return cur
};